package com.beijing.cyou.redis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.beijing.cyou.params.RedisParams;
import com.beijing.cyou.utils.NotNullHelps;

@Slf4j
@Service
public class RedisBasicService {

	@Autowired
	private RedisRepository redisBasic;

	private String stringValue;

	private boolean flag;

	public boolean chooseRedisPool(Integer dbnum) {
		return redisBasic.resetRedisPool(dbnum);
	}

	public boolean redisKeyExist(String redisKey){
		return redisBasic.redisKeyExist(redisKey);
	}

	public String getRedisStringValue(String key) throws Exception {
		log.info("## getRedisStringValue - success ! @@");
		stringValue = redisBasic.getString(key);
		return stringValue;
	}

	public void setRedisStringValue(String redisKey , String value)throws Exception {
		redisBasic.setString(redisKey, value);
	}

	public void insertToSet(String redisKey , String value)throws Exception {
		redisBasic.insertToSet(redisKey, value);
	}

	public String getRedisStringValueByDbnum(RedisParams condition) throws Exception {
		String key = condition.getKey();
		Integer dbnum = condition.getDbnum();
		if (NotNullHelps.checkNotNull(key, dbnum) == false) {
			log.info("## %%% 参数异常！ @@");
		} else {
			flag = this.chooseRedisPool(dbnum);
			if (flag == false) {
				log.info("@@ redis.pool 指定有误！ !!");
			} else {
				stringValue = redisBasic.getString(key);
				log.info("  value : " + stringValue);
			}
		}
		return stringValue;
	}
	
	

}
